package cn.webrx;

import java.util.Random;
import java.util.Stack;

public class Su2 {
    public static void main(String[] args) {
        long ss = System.currentTimeMillis();
        String letter = "~！@#￥%……&*,.<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        int len = 12;
        Random rand = new Random();
        char[] cs = new char[len];
        for (int i = 0; i < len; i++) {
            cs[i] = letter.charAt(rand.nextInt(letter.length()));
        }

        //new String(char[] ) 本质是将一个char[] 转换为String
        System.out.println(new String(cs));
        long ee = System.currentTimeMillis();
        System.out.println(ee - ss);

        sbu();

        str();

        Stack st = new Stack<>();


    }

    public static void sbu() {
        long ss = System.currentTimeMillis();
        String letter = "~！@#￥%……&*,.<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        int len = 12;
        Random rand = new Random();
        StringBuilder sbu = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            sbu.append(letter.charAt(rand.nextInt(letter.length())));
        }
        System.out.println(sbu);
        long ee = System.currentTimeMillis();
        System.out.println(ee - ss);
    }

    public static void str() {
        long ss = System.currentTimeMillis();
        String letter = "~！@#￥%……&*,.<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        int len = 12;
        Random rand = new Random();
        String pwd = "";
        for (int i = 0; i < len; i++) {
            pwd += letter.charAt(rand.nextInt(letter.length()));
        }
        System.out.println(pwd);
        long ee = System.currentTimeMillis();
        System.out.println(ee - ss);

    }
}
